home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7784 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: very simple newbie question
  5. Date: Wed, 28 Feb 96 18:52:46 GMT
  6. Organization: none
  7. Message-ID: <825533566snz@genesis.demon.co.uk>
  8. References: <robertk-2802960012350001@robertk.accessone.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <robertk-2802960012350001@robertk.accessone.com>
  15.            robertk@accessone.com "robertk" writes:
  16.  
  17. >             #include <stdio.h>
  18. >             main()
  19. >             {
  20. >              char s[10];
  21. >              scanf("%s/n",s);
  22.  
  23. I assume you meant \n   ^
  24.  
  25. >              printf("%s",s);
  26. >             }
  27. >
  28. >            when i run this and input:
  29. >
  30. >                  robert <enter> --->when i hit the enter key the cursor 
  31. >                                     drops down a line and sits ther flashing
  32. >                                     waiting for me to enter another character
  33. >                                     like x before it will throw me back to the
  34. >                                     ide. upon returning to the screen i see
  35. >                  robert
  36. >                  x
  37. >                  robert
  38. >
  39. >               i thought scanf() ignored whitespace?
  40.  
  41. When it sees a white-space character (such as '\n') in the format string it
  42. *skips* white-space. That means it continues to read characters until it
  43. encounters one that is not white-space or it encounters EOF. Therefore the
  44. scanf will continue to execute and read characters from the input stream
  45. until you type something that isn't purely white-space.
  46.  
  47. -- 
  48. -----------------------------------------
  49. Lawrence Kirby | fred@genesis.demon.co.uk
  50. Wilts, England | 70734.126@compuserve.com
  51. -----------------------------------------
  52.